Script to analyze larval size, symbiont density, and examine correlations between physiological responses.

Setup

Set up workspace, set options, and load required packages.

knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)

1. Larval Size

Import and manipulate data

# Larval size data
size <- read_csv("Mcap2020/Data/Physiology/Size/larval_size.csv")

#metadata
metadata <- read_csv("Mcap2020/Data/lifestage_metadata.csv")

size <- left_join(size, metadata)
size$hpf <- as.factor(size$hpf)

Prep data frame.

# Calculate mean counts for each sample
size <- size %>%
  dplyr::select(tube.ID, lifestage, replicate, `area (mm)`, hpf, group)%>%
  drop_na()%>% #remove na's that could not be measured
  rename(area=`area (mm)`) #rename column

size$lifestage<-as.factor(size$lifestage)

Plotting

Plot data with mean and standard error for each lifestage.

size %>%
  ggplot(aes(x = lifestage, y = area, color = lifestage)) +
  labs(x = "",y = "Mean Larval Size (mm^2)") +
geom_jitter(width = 0.1) +                                            # Plot all points
  stat_summary(fun.data = mean_cl_normal, fun.args = list(mult = 1),    # Plot standard error
               geom = "errorbar", color = "black", width = 0.5) +
  stat_summary(fun = mean, geom = "point", color = "black") + # Plot mean
  theme_classic()

Present means and standard error of each group and save summary table

size%>%
  group_by(lifestage, hpf)%>%
  summarise(n=length(area),
            Mean=format(round(mean(area), 3), 3), 
            SE=format(round(sd(area)/sqrt(length(area)),3),3))%>%
  rename(Lifestage=lifestage, HPF=hpf)%>%
  kbl(caption="Descriptive statistics of larval size across ontogeny")%>%
  kable_classic(full_width=FALSE, html_font="Arial")%>%
  row_spec(0, bold = TRUE) 
Descriptive statistics of larval size across ontogeny
Lifestage HPF n Mean SE
Egg Fertilized 1 40 0.19 0.004
Embryo 1 5 40 0.184 0.003
Larvae 1 38 40 0.258 0.005
Larvae 2 65 40 0.158 0.003
Larvae 3 93 40 0.184 0.003
Larvae 4 163 40 0.193 0.004
Larvae 5 183 40 0.196 0.005
Larvae 6 231 40 0.312 0.014
Recruit 1 183 40 0.193 0.006
Recruit 2 231 33 0.27 0.021
#need to output to csv 
size%>%
  group_by(lifestage, hpf)%>%
  summarise(n=length(area),
            Mean=format(round(mean(area), 3), 3), 
            SE=format(round(sd(area)/sqrt(length(area)),3),3))%>%
  rename(Lifestage=lifestage, HPF=hpf)%>%
  write_csv(., "Mcap2020/Output/Physiology/larval_size_table.csv")

Plot data as a scatterplot

size$hpf<-as.factor(size$hpf)
size_plot<-size %>%
    ggplot(., aes(x = hpf, y = area)) +
    #geom_boxplot(outlier.size = 0) +
    geom_smooth(method="loess", se=TRUE, fullrange=TRUE, level=0.95, color="black") +
    geom_point(aes(fill=group, group=group), pch = 21, size=4, position = position_jitterdodge(0.1)) + 
    xlab("Hours Post-Fertilization") + 
    scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
    ylab(expression(bold(paste("Planar Size (mm"^2, ")"))))+
    ylim(0,1)+
    theme_classic() + 
    theme(
      legend.position="right",
      axis.title=element_text(face="bold", size=14),
      axis.text=element_text(size=12, color="black"), 
      legend.title=element_text(face="bold", size=14), 
      legend.text=element_text(size=12)
      ); size_plot

#EGG: #8C510A
#EMBRYO: #DFC27D
#LARVAE: #80CDC1
#RECRUIT: #003C30

Plot data as box plot

size_plot2<-size %>%
    ggplot(., aes(x = hpf, y = area)) +
    geom_boxplot(aes(color=group), outlier.size = 0, lwd=1) +
    geom_point(aes(fill=group), pch = 21, size=2, position = position_jitterdodge(0.1)) + 
    xlab("Hours Post-Fertilization") + 
    scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
    scale_color_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
    ylab(expression(bold(paste("Planar Size (mm"^2, ")"))))+
    ylim(0, 0.8)+
    theme_classic() + 
    #geom_text(label="A", x=1, y=2500, size=4, color="black")+ #egg
    #geom_text(label="A", x=2, y=2500, size=4, color="black")+ #embryo 1
    #geom_text(label="A", x=3, y=2500, size=4, color="black")+ #larvae 1
    #geom_text(label="AB", x=4, y=4100, size=4, color="black")+ #larvae 2
    #geom_text(label="AB", x=5, y=4100, size=4, color="black")+ #larvae 3
    #geom_text(label="AB", x=6, y=4100, size=4, color="black")+ #larvae 4
    #geom_text(label="BC", x=6.8, y=4500, size=4, color="black")+ #larvae 5
    #geom_text(label="CD", x=7.2, y=6500, size=4, color="black")+ #recruit 1
    #geom_text(label="D", x=7.8, y=6500, size=4, color="black")+ #larvae6
    #geom_text(label="D", x=8.2, y=8700, size=4, color="black")+ #recruit2
    theme(
      legend.position="right",
      axis.title=element_text(face="bold", size=14),
      axis.text=element_text(size=12, color="black"), 
      legend.title=element_text(face="bold", size=14)
      ); size_plot2

Statistical analysis

Run lmer on cells per larvae by sampling point, specified by sequence of samples taken (life stage, hpf). Use tube ID as random effect.

size_model<-lmer(area~lifestage + (1|tube.ID), data=size)
summary(size_model)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: area ~ lifestage + (1 | tube.ID)
##    Data: size
## 
## REML criterion at convergence: -1149.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9918 -0.4117 -0.0292  0.3067  6.2690 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  tube.ID  (Intercept) 0.000000 0.00000 
##  Residual             0.002646 0.05144 
## Number of obs: 393, groups:  tube.ID, 40
## 
## Fixed effects:
##                      Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)          0.190150   0.008133 383.000000  23.381  < 2e-16 ***
## lifestageEmbryo 1   -0.005650   0.011501 383.000000  -0.491  0.62354    
## lifestageLarvae 1    0.068075   0.011501 383.000000   5.919 7.21e-09 ***
## lifestageLarvae 2   -0.031825   0.011501 383.000000  -2.767  0.00593 ** 
## lifestageLarvae 3   -0.006350   0.011501 383.000000  -0.552  0.58120    
## lifestageLarvae 4    0.003025   0.011501 383.000000   0.263  0.79268    
## lifestageLarvae 5    0.006000   0.011501 383.000000   0.522  0.60220    
## lifestageLarvae 6    0.122175   0.011501 383.000000  10.623  < 2e-16 ***
## lifestageRecruit 1   0.003225   0.011501 383.000000   0.280  0.77932    
## lifestageRecruit 2   0.079395   0.012096 383.000000   6.564 1.71e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) lfstE1 lfstL1 lfstL2 lfstL3 lfstL4 lfstL5 lfstL6 lfstR1
## lfstgEmbry1 -0.707                                                        
## lifestgLrv1 -0.707  0.500                                                 
## lifestgLrv2 -0.707  0.500  0.500                                          
## lifestgLrv3 -0.707  0.500  0.500  0.500                                   
## lifestgLrv4 -0.707  0.500  0.500  0.500  0.500                            
## lifestgLrv5 -0.707  0.500  0.500  0.500  0.500  0.500                     
## lifestgLrv6 -0.707  0.500  0.500  0.500  0.500  0.500  0.500              
## lifstgRcrt1 -0.707  0.500  0.500  0.500  0.500  0.500  0.500  0.500       
## lifstgRcrt2 -0.672  0.475  0.475  0.475  0.475  0.475  0.475  0.475  0.475
## optimizer (nloptwrap) convergence code: 0 (OK)
## boundary (singular) fit: see ?isSingular
qqPlot(residuals(size_model))

## [1] 361 383
leveneTest(residuals(size_model)~lifestage, data=size)
## Levene's Test for Homogeneity of Variance (center = median)
##        Df F value    Pr(>F)    
## group   9  12.196 < 2.2e-16 ***
##       383                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(size_model, type=2)
## Type II Analysis of Variance Table with Satterthwaite's method
##            Sum Sq  Mean Sq NumDF DenDF F value    Pr(>F)    
## lifestage 0.83148 0.092387     9   383   34.92 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Violation in normality and variance assumptions. Conduct non-parametric test (Kruskal Wallis).

kruskal.test(area~lifestage, data=size)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  area by lifestage
## Kruskal-Wallis chi-squared = 191.71, df = 9, p-value < 2.2e-16

Significant difference in size between lifestages.

View posthoc comparisons for differences between lifestages.

emm = emmeans(size_model, ~ lifestage)
cld(emm, Letters=c(LETTERS)) #letter display
##  lifestage      emmean      SE   df lower.CL upper.CL .group
##  Larvae 2        0.158 0.00813 29.0    0.142    0.175  A    
##  Larvae 3        0.184 0.00813 29.0    0.167    0.200  A    
##  Embryo 1        0.184 0.00813 29.0    0.168    0.201  A    
##  Egg Fertilized  0.190 0.00813 29.0    0.174    0.207  A    
##  Larvae 4        0.193 0.00813 29.0    0.177    0.210  A    
##  Recruit 1       0.193 0.00813 29.0    0.177    0.210  A    
##  Larvae 5        0.196 0.00813 29.0    0.180    0.213  A    
##  Larvae 1        0.258 0.00813 29.0    0.242    0.275   B   
##  Recruit 2       0.270 0.00897 38.9    0.251    0.288   B   
##  Larvae 6        0.312 0.00813 29.0    0.296    0.329    C  
## 
## Degrees-of-freedom method: kenward-roger 
## Confidence level used: 0.95 
## P value adjustment: tukey method for comparing a family of 10 estimates 
## significance level used: alpha = 0.05 
## NOTE: Compact letter displays can be misleading
##       because they show NON-findings rather than findings.
##       Consider using 'pairs()', 'pwpp()', or 'pwpm()' instead.

2. Symbiont Density

Symbiont density per individual

Import and manipulate data

# Cell count data
sym_counts <- read_csv("Mcap2020/Data/Physiology/CellDensity/symbiont.counts.csv")

sym_counts <- left_join(sym_counts, metadata)
sym_counts$hpf <- as.factor(sym_counts$hpf)

Calculate cells and normalize to either planar size (eggs through metamorphosed recruits) or surface area (attached recruits)

# Calculate mean counts for each sample
df <- sym_counts %>%
  dplyr::select(tube.ID, num.squares, matches("count[1-6]")) %>%
  gather("rep", "count", -tube.ID, -num.squares) %>%
  group_by(tube.ID, num.squares) %>%
  summarise(mean_count = mean(count, na.rm = TRUE))

#match in identifying information
df$lifestage<-sym_counts$lifestage[match(df$tube.ID, sym_counts$tube.ID)]
df$total.volume.ul<-sym_counts$total.volume.ul[match(df$tube.ID, sym_counts$tube.ID)]
df$num.individuals<-sym_counts$num.individuals[match(df$tube.ID, sym_counts$tube.ID)]
df$surface.area<-sym_counts$surface.area[match(df$tube.ID, sym_counts$tube.ID)]
df$hpf<-sym_counts$hpf[match(df$tube.ID, sym_counts$tube.ID)]
df$group<-sym_counts$group[match(df$tube.ID, sym_counts$tube.ID)]
df$lifestage<-as.factor(df$lifestage)
df$group<-as.factor(df$group)

# Normalize counts by homogenat volume and surface area
df <- df %>%
  mutate(cells.mL = mean_count * 10000 / num.squares,
         cells = cells.mL * (total.volume.ul/1000),
         cells.ind = cells / num.individuals, 
         cells.mm = cells / surface.area)

sym_counts<-df

Plotting

Plot data with mean and standard error for larvae through metamorphosis (these counts have cells/individual). Plot attached recruits separately, these values are in cells per mm2. We will plot cells per unit surface area for all stages in later analyses.

Display cells per individual.

sym_counts %>%
  filter(!group=="Attached Recruit")%>%
  ggplot(aes(x = lifestage, y = cells.ind, color = lifestage)) +
  labs(x = "",y = "Cell Density per larva") +
geom_jitter(width = 0.1) +                                            # Plot all points
  stat_summary(fun.data = mean_cl_normal, fun.args = list(mult = 1),    # Plot standard error
               geom = "errorbar", color = "black", width = 0.5) +
  stat_summary(fun = mean, geom = "point", color = "black") + # Plot mean
  theme_classic()

Display cell density per mm2 in attached recruit plugs. Plug 1 = 48 hps, Plug 2 = 72 hps, Plug 3 = 96 hps

sym_counts %>%
  filter(group=="Attached Recruit")%>%
  ggplot(aes(x = lifestage, y = cells.mm, color = lifestage)) +
  labs(x = "",y = "Cell Density per mm2") +
geom_jitter(width = 0.1) +                                            # Plot all points
  #stat_summary(fun.data = mean_cl_normal, fun.args = list(mult = 1),    # Plot standard error
               #geom = "errorbar", color = "black", width = 0.5) +
  #stat_summary(fun.y = mean, geom = "point", color = "black") + # Plot mean
  theme_classic()

Present means and standard error of each group and save summary table.

sym_counts%>%
  group_by(group, hpf, lifestage)%>%
  summarise(n=length(cells.ind),
            Mean=format(round(mean(cells.ind), 0), 0), 
            SE=format(round(sd(cells.ind)/sqrt(length(cells.ind)),0),0))%>%
  rename(Lifestage=group, HPF=hpf)%>%
  kbl(caption="Descriptive statistics of Symbiodiniaceae cell densities per larva across ontogeny")%>%
  kable_classic(full_width=FALSE, html_font="Arial")%>%
  row_spec(0, bold = TRUE) 
Descriptive statistics of Symbiodiniaceae cell densities per larva across ontogeny
Lifestage HPF lifestage n Mean SE
Attached Recruit 183 Plug 1 3 NA NA
Attached Recruit 231 Plug 2 2 NA NA
Attached Recruit 255 Plug 3 3 NA NA
Egg 1 Egg Fertilized 4 1472 125
Embryo 5 Embryo 1 4 1831 124
Embryo 38 Larvae 1 4 1371 242
Embryo 65 Larvae 2 4 2646 238
Larvae 93 Larvae 3 4 2692 347
Larvae 163 Larvae 4 4 2848 206
Larvae 183 Larvae 5 4 3474 134
Larvae 231 Larvae 6 4 5142 386
Metamorphosed Recruit 183 Recruit 1 4 4829 480
Metamorphosed Recruit 231 Recruit 2 4 6424 659
sym_counts%>%
  group_by(group, hpf, lifestage)%>%
  summarise(n=length(cells.mm),
            Mean=format(round(mean(cells.mm), 0), 0), 
            SE=format(round(sd(cells.mm)/sqrt(length(cells.mm)),0),0))%>%
  rename(Lifestage=group, HPF=hpf)%>%
  kbl(caption="Descriptive statistics of Symbiodiniaceae cell densities per mm2 across ontogeny")%>%
  kable_classic(full_width=FALSE, html_font="Arial")%>%
  row_spec(0, bold = TRUE) 
Descriptive statistics of Symbiodiniaceae cell densities per mm2 across ontogeny
Lifestage HPF lifestage n Mean SE
Attached Recruit 183 Plug 1 3 21503 3084
Attached Recruit 231 Plug 2 2 30977 185
Attached Recruit 255 Plug 3 3 42014 3847
Egg 1 Egg Fertilized 4 NA NA
Embryo 5 Embryo 1 4 NA NA
Embryo 38 Larvae 1 4 NA NA
Embryo 65 Larvae 2 4 NA NA
Larvae 93 Larvae 3 4 NA NA
Larvae 163 Larvae 4 4 NA NA
Larvae 183 Larvae 5 4 NA NA
Larvae 231 Larvae 6 4 NA NA
Metamorphosed Recruit 183 Recruit 1 4 NA NA
Metamorphosed Recruit 231 Recruit 2 4 NA NA
#need to output to csv 
sym_counts%>%
  group_by(group, hpf, lifestage)%>%
  summarise(n=length(cells.ind),
            Mean=format(round(mean(cells.ind), 0), 0), 
            SE=format(round(sd(cells.ind)/sqrt(length(cells.ind)),0),0))%>%
  rename(group=group, HPF=hpf)%>%
  write_csv(., "Mcap2020/Output/Physiology/cell_density_table.csv")

Plot data as a scatterplot

sym_counts$hpf<-as.numeric(as.character(sym_counts$hpf))

symb_plot<-sym_counts %>%
    filter(!group=="Attached Recruit")%>%
    droplevels()%>%
    ggplot(., aes(x = hpf, y = cells.ind)) +
    #geom_boxplot(outlier.size = 0) +
    geom_smooth(method="lm", se=TRUE, fullrange=TRUE, level=0.95, color="black") +
    geom_point(aes(fill=group, group=group), pch = 21, size=4, position = position_jitterdodge(5)) + 
    xlab("Hours Post-Fertilization") + 
    scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
    ylab(expression(bold(paste("Symbiont cells individual"^-1))))+
    ylim(0,9000)+
    theme_classic() + 
    theme(
      legend.position="right",
      axis.title=element_text(face="bold", size=14),
      axis.text=element_text(size=12, color="black"), 
      legend.title=element_text(face="bold", size=14), 
      legend.text=element_text(size=12)
      ); symb_plot

#EGG: #8C510A
#EMBRYO: #DFC27D
#LARVAE: #80CDC1
#RECRUIT: #003C30
#ATTACHED: #BA55D3

Plot data as box plot

symb_plot2<-sym_counts %>%
    filter(!group=="Attached Recruit")%>%
    droplevels()%>%
    ggplot(., aes(x = as.factor(hpf), y = cells.ind)) +
    geom_boxplot(aes(color=group), outlier.size = 0, lwd=1) +
    #geom_smooth(method="loess", se=TRUE, fullrange=TRUE, level=0.95, color="black") +
    geom_point(aes(fill=group), pch = 21, size=4, position = position_jitterdodge(0.2)) + 
    xlab("Hours Post-Fertilization") + 
    scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
    scale_color_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"), guide="none")+
    ylab(expression(bold(paste("Symbiont cells individual"^-1))))+
    ylim(0,9000)+
    theme_classic() + 
    theme(
      legend.position="right",
      axis.title=element_text(face="bold", size=14),
      axis.text=element_text(size=12, color="black"), 
      legend.title=element_text(face="bold", size=14)
      ); symb_plot2

Statistical analysis

Run ANOVA on cells per larvae by sampling point, specified by sequence of samples taken (life stage, hpf).

sym_ind_model_data<-sym_counts%>%
      filter(!group=="Attached Recruit")%>%
      droplevels()

sym_ind_model<-aov(cells.ind~lifestage, data=sym_ind_model_data)
summary(sym_ind_model)
##             Df    Sum Sq  Mean Sq F value   Pr(>F)    
## lifestage    9 102932981 11436998   25.06 1.34e-11 ***
## Residuals   30  13689458   456315                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
qqPlot(residuals(sym_ind_model))

## [1] 33 30
leveneTest(residuals(sym_ind_model)~lifestage, data=sym_ind_model_data)
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group  9  1.7683 0.1166
##       30

Both normality and homogeneity of variance pass.

There is a significant effect of lifestage on cell densities. View posthoc comparisons for differences between lifestages.

emm = emmeans(sym_ind_model, ~ lifestage)
cld(emm, Letters=c(LETTERS)) #letter display
##  lifestage      emmean  SE df lower.CL upper.CL .group
##  Larvae 1         1371 338 30      681     2061  A    
##  Egg Fertilized   1472 338 30      782     2161  A    
##  Embryo 1         1831 338 30     1141     2521  A    
##  Larvae 2         2646 338 30     1956     3335  AB   
##  Larvae 3         2692 338 30     2002     3382  AB   
##  Larvae 4         2848 338 30     2158     3538  AB   
##  Larvae 5         3474 338 30     2784     4163   BC  
##  Recruit 1        4829 338 30     4139     5519    CD 
##  Larvae 6         5142 338 30     4452     5831     D 
##  Recruit 2        6424 338 30     5734     7114     D 
## 
## Confidence level used: 0.95 
## P value adjustment: tukey method for comparing a family of 10 estimates 
## significance level used: alpha = 0.05 
## NOTE: Compact letter displays can be misleading
##       because they show NON-findings rather than findings.
##       Consider using 'pairs()', 'pwpp()', or 'pwpm()' instead.

Output data to file.

sym_counts %>%
  write_csv(., file = "Mcap2020/Output/Physiology/calculated_densities.csv")

Symbiont density per unit size

Data manipulation and correlation

First, test for correlation between symbiont cell density and larval size to see if there is a relationship.

Generate data frame with summarised size and cell density information for each time point from eggs to metamorphosed recruits, because we have data for size and counts for each sample. We do not include attached recruits here yet, becuase we cannot calculate densities per individual.

#read in data frame generated in previous chunk 
sym_counts<-sym_counts%>%
  dplyr::select(tube.ID, lifestage, group, hpf, cells.ind, cells.mm)

#grab size data
area<-size%>%
  group_by(tube.ID)%>%
  summarise(mean_area=mean(area, na.rm=TRUE))

area$tube.ID<-as.factor(area$tube.ID)
sym_counts$hpf<-as.factor(sym_counts$hpf)

corr<-left_join(sym_counts, area)

Generate number of symbiont cells per mm^2 area for each tube.

corr<-corr%>%
  mutate(counts_area=cells.ind/mean_area)%>%
  mutate(counts_area=ifelse(is.na(counts_area), cells.mm, counts_area)) #add attached recruit data already calculated as cells per mm2

Plot correlation between cell counts (cells per individual) and size (area mm^2).

correlation<-corr %>%
    filter(!group=="Attached Recruit")%>%
    ggplot(., aes(x = mean_area, y = cells.ind)) +
    #geom_smooth(method="lm", se=TRUE, fullrange=TRUE, level=0.95, color="black", fill="gray") +
    geom_point(aes(fill=group), pch = 21, size=4) + 
    xlab(expression(bold(paste("Larval Size (mm"^2, ")")))) + 
    scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
    scale_color_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30"))+
    xlab(expression(bold(paste("Individual Size (mm"^2, ")"))))+
    ylab(expression(bold(paste("Symbiont cells individual"^-1))))+
    #ylim(0, 9000)+
    theme_classic() + 
    theme(
      legend.position="none",
      axis.title=element_text(face="bold", size=14),
      axis.text=element_text(size=12, color="black"), 
      legend.title=element_text(face="bold", size=14)
      ); correlation

Test relationship with a spearman correlation.

cor.test(corr$mean_area, corr$cells.ind, method=c("spearman"))
## 
##  Spearman's rank correlation rho
## 
## data:  corr$mean_area and corr$cells.ind
## S = 6658, p-value = 0.01753
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##       rho 
## 0.3754221

Significant correlation between size and cell counts. r=0.37, p=0.017

Plotting

Plot cells per mm^2 as a boxplot.

#order for creating a legend for all plots 
corr$group <- factor(corr$group, levels = c("Egg", "Embryo", "Larvae", "Metamorphosed Recruit", "Attached Recruit"))

cells_size_plot<-corr %>%
    ggplot(., aes(x = hpf, y = counts_area)) +
    geom_boxplot(aes(color=group), outlier.size = 0, lwd=1) +
    geom_point(aes(fill=group), pch = 21, size=4, position = position_jitterdodge(0.4)) + 
    xlab("Hours Post-Fertilization") + 
    scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30", "#BA55D3"), guide="none")+
    scale_color_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30", "#BA55D3"))+
    ylab(expression(bold(paste("Symbiont cells mm"^-2))))+
    #ylim(2000, 35000)+
    theme_classic() + 
    theme(
      legend.position="right",
      axis.title=element_text(face="bold", size=14),
      axis.text=element_text(size=12, color="black"), 
      legend.title=element_text(face="bold", size=14)
      ); cells_size_plot

Plot as linear relationship.

cells_size_plot2<-corr %>%
    ggplot(., aes(x = as.numeric(as.character(hpf)), y = counts_area)) +
    #geom_boxplot(aes(color=group), outlier.size = 0, lwd=1) +
    geom_point(aes(fill=group, group=group), pch = 21, size=4, position = position_jitterdodge(0.4)) + 
    geom_smooth(method="lm", se=TRUE, fullrange=TRUE, level=0.95, color="black") +
    xlab("Hours Post-Fertilization") + 
    scale_fill_manual(name="Lifestage", values=c("#8C510A", "#DFC27D","#80CDC1", "#003C30", "#BA55D3"), guide="none")+
    scale_color_manual(name="Lifestage", values=c( "#8C510A", "#DFC27D","#80CDC1", "#003C30", "#BA55D3"))+
    ylab(expression(bold(paste("Symbiont cells mm"^-2))))+
    #ylim(2000, 35000)+
    theme_classic() + 
    theme(
      legend.position="right",
      axis.title=element_text(face="bold", size=14),
      axis.text=element_text(size=12, color="black"), 
      legend.title=element_text(face="bold", size=14)
      ); cells_size_plot2

Analyze differences in normalized cell counts by timepoint.

model<-corr%>%
  #filter(!group=="Attached Recruit")%>%
  #droplevels()%>%
  aov(counts_area~lifestage, data=.)

qqPlot(residuals(model))

## [1] 41 30
corr%>%
  #filter(!group=="Attached Recruit")%>%
  #droplevels()%>%
  leveneTest(residuals(model)~lifestage, data=.)
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value Pr(>F)
## group 12  1.2849 0.2704
##       35
summary(model)
##             Df    Sum Sq   Mean Sq F value   Pr(>F)    
## lifestage   12 3.847e+09 320569728   26.84 4.08e-14 ***
## Residuals   35 4.180e+08  11943131                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

View posthoc differences.

emm = emmeans(model, ~ lifestage)
cld(emm, Letters=c(LETTERS)) #letter display
##  lifestage      emmean   SE df lower.CL upper.CL .group  
##  Larvae 1         5285 1728 35     1777     8793  A      
##  Egg Fertilized   7746 1728 35     4238    11254  AB     
##  Embryo 1         9923 1728 35     6416    13431  ABC    
##  Larvae 4        14732 1728 35    11224    18240   BCD   
##  Larvae 3        14756 1728 35    11248    18264   BCD   
##  Larvae 6        16510 1728 35    13002    20018    CDE  
##  Larvae 2        16867 1728 35    13359    20374    CDE  
##  Larvae 5        17732 1728 35    14224    21240    CDE  
##  Plug 1          21503 1995 35    17452    25554     DEF 
##  Recruit 2       23301 1728 35    19793    26809     DEF 
##  Recruit 1       25137 1728 35    21629    28644      EF 
##  Plug 2          30977 2444 35    26016    35938       FG
##  Plug 3          42014 1995 35    37964    46065        G
## 
## Confidence level used: 0.95 
## P value adjustment: tukey method for comparing a family of 13 estimates 
## significance level used: alpha = 0.05 
## NOTE: Compact letter displays can be misleading
##       because they show NON-findings rather than findings.
##       Consider using 'pairs()', 'pwpp()', or 'pwpm()' instead.

Generate summary table of descriptive statistics.

#need to output to csv 
corr%>%
  group_by(group, hpf, lifestage)%>%
  summarise(n=length(counts_area),
            Mean_sym_mm2=format(round(mean(counts_area), 0), 0), 
            SE=format(round(sd(counts_area)/sqrt(length(counts_area)),0),0))%>%
  rename(Lifestage=group, HPF=hpf)%>%
  write_csv(., "Mcap2020/Output/Physiology/normalized_size_cells_summary.csv")

3. Correlations

Respirometry correlated with density

Load dataframes

resp<-read.csv("Mcap2020/Output/Respiration/mean_respiration.csv")
size<-read.csv("Mcap2020/Output/Physiology/larval_size_table.csv")
size_density<-read.csv("Mcap2020/Output/Physiology/normalized_size_cells_summary.csv")
density<-read.csv("Mcap2020/Output/Physiology/cell_density_table.csv")

Standardize column names.

resp<-resp%>%
    rename(Lifestage=group)%>%
    dplyr::select(Lifestage, Mean_R, Mean_P, Mean_GP, Mean_PR)

resp$Lifestage<-as.factor(resp$Lifestage)

levels(resp$Lifestage) <- list(`Larvae 2` = "Larvae2", `Larvae 3`  = "Larvae3", `Larvae 5`  = "Larvae5", `Larvae 6`  = "Larvae6", `Recruit 1`  = "Recruit1", `Recruit 2`  = "Recruit2")

size<-size%>%
  dplyr::select(Lifestage, Mean)%>%
  rename(Mean_Size=Mean)

size$Lifestage<-as.factor(size$Lifestage)

size_density<-size_density%>%
  dplyr::select(lifestage, Mean_sym_mm2)%>%
  rename(Mean_Size_Density=Mean_sym_mm2, Lifestage=lifestage)

size_density$Lifestage<-as.factor(size_density$Lifestage)

density<-density%>%
    rename(Lifestage=lifestage, Mean_Density=Mean)%>%
  dplyr::select(Lifestage, Mean_Density)

density$Lifestage<-as.factor(density$Lifestage)

Combine dataframes.

master<-full_join(resp, size, by=c("Lifestage"))

master<-full_join(master, size_density, by=c("Lifestage"))

master<-full_join(master, density, by=c("Lifestage"))

head(master)
##   Lifestage      Mean_R      Mean_P    Mean_GP  Mean_PR Mean_Size
## 1  Larvae 2 -0.01886538 0.011875684 0.03074106 1.767823     0.158
## 2  Larvae 3 -0.01364444 0.013637833 0.02728227 2.139497     0.184
## 3  Larvae 5 -0.01967560 0.032156372 0.05183197 2.705802     0.196
## 4  Larvae 6 -0.02208091 0.032023557 0.05410447 2.446370     0.312
## 5 Recruit 1 -0.05541750 0.002830864 0.05824836 1.120693     0.193
## 6 Recruit 2 -0.04029479 0.014010579 0.05430537 1.358576     0.270
##   Mean_Size_Density Mean_Density
## 1             16867         2646
## 2             14756         2692
## 3             17732         3474
## 4             16510         5142
## 5             25137         4829
## 6             23301         6424

Generate correlation matrix

Check for correlations between all variables.

pdf("Mcap2020/Figures/Physiology/Correlations.pdf", height = 9, width = 9)
g <-ggpairs(master, columns=2:8)
print(g)
dev.off()
## quartz_off_screen 
##                 2

There is a significant correlation between size normalized symbiont cell density and respiration. Plot this relationship.

Run Pearson correlation between respiration and size normalized cell densities.

cor<-master%>%
  drop_na()

cor.test(cor$Mean_Size_Density, cor$Mean_R, method=c("pearson"))
## 
##  Pearson's product-moment correlation
## 
## data:  cor$Mean_Size_Density and cor$Mean_R
## t = -8.9183, df = 4, p-value = 0.0008739
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.9974514 -0.7890338
## sample estimates:
##        cor 
## -0.9757648

There is a significant correlation r=-0.98, p=0.0009.

r_corr_plot<-master %>%
    drop_na()%>%
    ggplot(., aes(x = Mean_Size_Density, y = Mean_R)) +
    #geom_smooth(method="glm", se=FALSE, fullrange=TRUE, level=0.95, color="gray", fill="gray") +
    geom_point(aes(fill=Lifestage), pch = 21, size=4) + 
    xlab(expression(bold(paste("Symbiont cells mm"^-2)))) + 
    scale_fill_manual(name="Lifestage", values=c("#DFC27D", "#80CDC1","#80CDC1", "#80CDC1", "#003C30", "#003C30"))+
    scale_color_manual(name="Lifestage", values=c("#DFC27D", "#80CDC1","#80CDC1", "#80CDC1", "#003C30", "#003C30"))+
    ylab(expression(bold(paste("Respiration (nmol O2) individual"^-1))))+
    #ylim(0, 9000)+
    theme_classic() + 
    theme(
      legend.position="right",
      axis.title=element_text(face="bold", size=14),
      axis.text=element_text(size=12, color="black"), 
      legend.title=element_text(face="bold", size=14)
      ); r_corr_plot

4. Generate Figures

Generate physiology panel with all variables of interest.

# extract the legend from one of the plots
legend <- get_legend(
  # create some space to the left of the legend
  cells_size_plot + theme(legend.box.margin = margin(1,1,1,1))
)

#remove legends from plots  
size_plot2<-size_plot2+theme(legend.position="none")
symb_plot2<-symb_plot2+theme(legend.position="none")
r_corr_plot<-r_corr_plot+theme(legend.position="none")
cells_size_plot_l<-cells_size_plot+theme(legend.position="none")

#assemble plots
all_plots<-plot_grid(size_plot2, symb_plot2, cells_size_plot_l, r_corr_plot, labels = c("A", "B", "C", "D"), label_size=18, ncol=4, nrow=1, rel_heights= c(1,1,1,1), rel_widths = c(1,1,1,0.8), align="h")

all_plots_legend<-plot_grid(all_plots, legend, rel_widths = c(4, 0.5), ncol=2, nrow=1)

ggsave(file="Mcap2020/Figures/Physiology/Physiology_figure.pdf", all_plots_legend, dpi=300, width=24, height=6, units="in")
ggsave(file="Mcap2020/Figures/Physiology/Physiology_figure.png", all_plots_legend, dpi=300, width=24, height=6, units="in")

Early life history physiology